/**
 * @author wuwenfa
 */
public class Good implements Comparable<Good> {
    //    （id, 名称，分类，售价，创建时间）
    private int id;
    private String name;
    private String category;
    private double sellPrice;
    private int createdAt;

    public Good(int id, String name, String category, double sellPrice, int createdAt) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.sellPrice = sellPrice;
        this.createdAt = createdAt;
    }

    @Override
    public String toString() {
        return "{" +
                "\"id\":" + id +
                ",\"name\":\"" + name +
                "\", \"category\":\"" + category +
                "\", \"sellPrice\":" + sellPrice +
                ", \"createdAt\":" + createdAt +
                "}";
    }

    @Override
    public int compareTo(Good good) {
        return good.createdAt - createdAt;
    }

    @Override
    public int hashCode() {
        return id + name.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof Good) {
            Good g = (Good) o;
            return this.id == g.id && this.name.equals(g.name) && this.category.equals(g.category) &&
                    this.sellPrice == g.sellPrice && this.createdAt == g.createdAt;
        }
        return false;
    }

}
